#!/usr/bin/python
# -*- coding: utf-8 -*-

import csv
import numpy as np
with open('out.csv', 'rb') as csvfile:
    titanic_reader = csv.reader(csvfile, delimiter=',',quotechar='"')


    # Header contains feature names
    row = titanic_reader.next()
    feature_names = np.array(row)


    # Load dataset, and target classes
    titanic_X, titanic_y = [], []
    for row in titanic_reader:
        titanic_X.append(row)
        titanic_y.append(row[2]) # The target value is "survived"

    titanic_X = np.array(titanic_X)
    titanic_y = np.array(titanic_y)

    print feature_names

    print titanic_X[0], titanic_y[0]

#adaptado ao nosso csv temos o timestamp, iporig,ipdst
titanic_X = titanic_X[:, [0, 2, 3]]
feature_names = feature_names[[0, 2, 3]]

print feature_names

print titanic_X[1],titanic_y[1]

# Para o caso de existir valores em falta, neste caso estes são substituidos pela media no dataset

#ages = titanic_X[:, 1]
#mean_age = np.mean(titanic_X[ages != 'NA',1].astype(np.float))
#titanic_X[titanic_X[:, 1] == 'NA', 1] = mean_age
